"""
@File    :   models.py
@Time    :   2024/02/19 14:29:27
@Author  :   Qrj
@Email   :   923207736@qq.com
@description   :   社交登录用户与后台用户绑定数据模型
"""

from datetime import datetime

from sqlalchemy import BigInteger, Column, DateTime, Integer, UniqueConstraint

from src.models.models import OrmBase


class SocialUserBind(OrmBase):
    """社交登录用户与后台用户绑定数据模型"""

    __tablename__ = "system_social_user_bind"
    __table_args__ = (UniqueConstraint("user_id", "social_user_id", "tenant_id"),)
    id = Column(BigInteger(), primary_key=True, autoincrement=True, comment="主键")
    create_datetime = Column(
        DateTime(), nullable=False, default=datetime.now, index=True, comment="创建时间"
    )
    update_datetime = Column(
        DateTime(),
        nullable=False,
        default=datetime.now,
        onupdate=datetime.now,
        index=True,
        comment="修改时间",
    )
    # 租户ID(级联删除)
    tenant_id = Column(BigInteger(), nullable=False, index=True, comment="租户ID")
    # 用户ID(级联删除)
    user_id = Column(BigInteger(), nullable=False, index=True, comment="用户ID")
    # 社交用户ID(级联删除)
    social_user_id = Column(Integer(), index=True, nullable=False, comment="社交用户ID")
